Skip to content

[rcore] Fix FileCopy() and FileMove() reporting success when the copy failed - #6364

Merged
raysan5 merged 2 commits into
raysan5:masterfrom
b84330808:fix-filecopy-result
Nov 10, 2026
Merged

raysan5 merged 2 commits into
raysan5:masterfrom
b84330808:fix-filecopy-result

Conversation

@b84330808

Copy link
Copy Markdown
Contributor

Since #5920, FileCopy() sets result = 0 once the destination directory exists and never resets it, so it returns 0 when the source doesn't exist or is empty, or when the destination can't be written (read-only file, a directory, ...).

FileMove() relies on that result and then only checks that the destination exists with the same size. When the destination is an existing read-only file of the same size, nothing is copied but the source file is removed.

SaveFileText("a.txt", "AAAAA");
SaveFileText("b.txt", "BBBBB");   // then mark b.txt read-only
FileMove("a.txt", "b.txt");       // returns 0, a.txt is gone, b.txt still has BBBBB

FileCopy() now returns 0 only when the data was saved, and FileMove() returns -1 when the copied file doesn't check out.

…copy failed

Since raysan5#5920, `FileCopy()` sets `result` to 0 once the destination
directory exists and never resets it, so it returns 0 when the source
is missing or empty or when the destination can't be written.

`FileMove()` trusts that result. If the destination is an existing file
of the same size that can't be overwritten (e.g. read-only), the length
check passes and the source file is removed although nothing was copied.

Only return 0 from `FileCopy()` when the data was saved, and make
`FileMove()` return -1 when the copied file does not check out.
Comment thread src/rcore.c Resolved
@raysan5
raysan5 merged commit 3ade998 into raysan5:master Nov 10, 2026
16 checks passed
@raysan5

raysan5 commented Nov 10, 2026

Copy link
Copy Markdown
Owner

@b84330808 thanks for the review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants